
<form id="form_bon_retour" method="post" {{ form_enctype(form) }}>
    <div class="span12">
        <div class="box gradient">
            <div class="title" style="text-align: center">
                <h4>Bon Retour Client</h4>
            </div>

            <div class="content noPad clearfix">
                <table style="width: 100%">
                    <tr>
                        <td style="width: 20%">
                            <label>Date:</label>
                            <div>
                                    {{ form_widget(form.date)}}{{ form_widget(form._token)}}
                                    <input id="now" type="text" style="width: 70px;" readonly/> 
                                </div>
                            </td>
                            <td  style="width: 20%">
                                <label>Client:</label>
                                <div  style="width: 200px">
                                    {{ form_widget(form.client,{'attr':{'class':'nostyle','style':'width:100%'}})}}
                                    </div> 
                                </td>
                                <td  style="width: 20%">
                                    <label>Departement:</label>
                                    <div style="width: 200px">
                                    {{ render(controller('GdsVenteBundle:Devis:getAllDepartement')) }}
                                        </div> 
                                    </td>
                                    <td  style="width: 40%">
                                        <label>Numero Bon Retour:</label>
                                {{ form_widget(form.reference,{'attr':{'class':'span8 text','readonly':'readonly','style':'width:200px'}})}}
                                    </td>
                                </tr>
                            </table>

                        </div> 
                    </div>
                </div>
            </form>

            <div class="span12" style="margin-left:0">
                <table>
                    <tr>
                        <td id="td_articles">
                            <input type="text" id="articles" style="width:100%"/>
                        </td>
                    </tr>
                </table>
                <div class="box gradient">
                    <div class="content noPad clearfix">
                        <table id="table_bon_retour" cellpadding="0" cellspacing="0" border="0" class="responsive  display table table-bordered" width="100%">
                            <thead>
                                <tr >
                                    <th>N°</th>
                                    <th>Reference</th>
                                    <th>Designation</th>
                                    <th>Qte Retour</th>
                                    <th id="th_dispo" style="width:5%">Qte Prise</th>
                                    <th>P.U.HT</th>
                                    <th>TVA</th>
                                    <th>Remise</th>
                                    <th>P.U.TTC</th>
                                    <th id="th_total" style="width:10%">Total</th>
                                    <th id="ok"></th>
                                </tr>
                            </thead>
                            <tbody id="gds_ventebundle_lignebonretour">
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="span2" style="margin-left:83%">
                    <div class="content noPad clearfix">
                        <table cellpadding="0" cellspacing="0" border="1px" class="responsive  display table table-bordered" width="100%" style="border:#D0E9F5 ">
                            <thead>
                                <tr >
                                    <th class="center" style="text-align: center">TOTAL TTC</th>
                                    <th id="total_ttc" class="center">0.000</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
    {# Ajout d'un lien pour ajouter un champ cat�gorie suppl�mentaire. #}
            <div class="span2" style="margin-left:0">
                <div class="box gradient">
                    <div class="content noPad clearfix">
                        <table id="taxe" cellpadding="0" cellspacing="0" border="0" class="responsive  display table table-bordered" width="100%">
                            <thead>
                                <tr>
                                    <th>Taxe</th>
                                    <th>Base</th>
                                    <th>Montant</th>
                                </tr>
                            </thead>
                            <tbody id="taxe_body">
                                <tr id="tr_taxe_18">
                                    <td id="taxe_18">18%</td>
                                    <td id="base_18">0.000</td>
                                    <td id="montant_taxe_18">0.000</td>
                                </tr>
                                <tr>
                                    <td>Totaux</td>
                                    <td></td>
                                    <td id="total_taxe">0.000</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="span2" style="margin-right: 0">
                <table>
                    <tr>
                        <td style="text-align: center">
                            <input type="button" style="width:100px" id="submit_form_bon_retour" value="Enregistrer" class="nostyle btn btn-success btn-large" />
                        </td>
                        <td style="text-align: center">
                            <input type="button" style="width:100px" id="submit_form_bon_retour_print" value="Imprimer" onclick="EnregistrerImprimer()" class="nostyle btn btn-success btn-large" />
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 20px"></td>
                    </tr>
                </table>
            </div>
            <input type="hidden" id="heure"/>
            <script>
                                $(document).ready(function() {
                                    $('#gds_ventebundle_bonlivraisonretourclienttype_client').val({{client.id}})
                                    $('#gds_ventebundle_bonlivraisonretourclienttype_client').attr('disabled', true);
                                    $('#departement').val({{user.departement.id}})
                                    $('#departement').attr('disabled', true);
                                    $('#gds_ventebundle_bonlivraisonretourclienttype_date').datepicker();
                                    var fullDate = new Date();
                                    var twoDigitMonth = fullDate.getMonth()
                                    twoDigitMonth++
                                    twoDigitMonth += "";
                                    if (twoDigitMonth.length == 1)
                                        twoDigitMonth = "0" + twoDigitMonth;
                                    var twoDigitDate = fullDate.getDate() + "";
                                    if (twoDigitDate.length == 1)
                                        twoDigitDate = "0" + twoDigitDate;
                                    var currentDate = twoDigitDate + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
                                    $("#gds_ventebundle_bonlivraisonretourclienttype_date").val(currentDate)
                                    setInterval(time, 1000);
                                    ids = new Array()
                                    {% for id in ids %}
                                    ids[ids.length] = {{id}}
                                    {% endfor %}

                                    $('#submit_form_bon_retour').click(function() {
                                        $('#gds_ventebundle_bonlivraisonretourclienttype_reference').focus()
                                        $.ajax({
                                            url: '{{path("gds_vente_bon_retour")}}',
                                            type: "POST",
                                            datatype: 'json',
                                            data: $('#form_bon_retour').serialize() + '&articles=' + JSON.stringify(articles) + '&ids=' + JSON.stringify(ids) + '&heure=' + $('#heure').val(),
                                            success: function(data) {
                                                if (data.success) {
                                                    $.msgBox({
                                                        title: "Bon Livraison Retour",
                                                        content: "Enregistrement Effectué avec succés",
                                                        type: "info",
                                                        buttons: [{value: "OK"}],
                                                        success: function(result) {
                                                            location.reload();
                                                        }
                                                    });
                                                } else {
                                                    $.msgBox({
                                                        title: "Bon Livraison Retour",
                                                        content: "Erreur D'enregistrement",
                                                        type: "error",
                                                        buttons: [{value: "OK"}]
                                                    });
                                                }
                                            },
                                            error: function(e) {
                                                $.msgBox({
                                                    title: "Bon Livraison Retour",
                                                    content: "Erreur D'enregistrement",
                                                    type: "error",
                                                    buttons: [{value: "OK"}]
                                                });
                                            }
                                        })
                                    })

                                    index = 0;
                                    nb_article = 1;
                                    articles = new Array();
                                    $container = $('#gds_ventebundle_lignebonretour');
                                    $.ajax({
                                        url: '{{path('gds_vente_get_articles_from_bls')}}',
                                        datatype: 'json',
                                        data: 'ids=' + JSON.stringify(ids),
                                        success: function(data) {
                                            $("#articles").tokenInput(data, {
                                                preventDuplicates: true,
                                                onAdd: function(item) {
                                                    ajouterArticle(item)
                                                },
                                            });
                                        }
                                    })
                                    article_added = false;
                                    $('#gds_ventebundle_bonlivraisonretourclienttype_reference').dblclick(function() {
                                        if (!article_added) {
                                            $.msgBox({
                                                title: "Charger tous les articles & remise non limité",
                                                content: "mdp: <input id='mdp' type='password' />",
                                                type: "confirm",
                                                buttons: [
                                                    {type: "submit", value: "Valider"},
                                                    {type: "cancel", value: "Annuler"}
                                                ],
                                                afterShow: function() {
                                                    $('#mdp').focus()
                                                },
                                                success: function(result) {
                                                    if (result == "Valider") {
                                                        if ($('#mdp').val() != '') {
                                                            $.ajax({
                                                                url: '{{path('gds_vente_is_password_true')}}',
                                                                data: 'password=' + $('#mdp').val(),
                                                                success: function(data) {
                                                                    if (data == 'true') {
                                                                        article_added = true
                                                                        for (var i = 0; i < index; i++) {
                                                                            var article = getArticle($('#gds_ventebundle_' + i + '_article').val())
                                                                            $('#gds_ventebundle_' + i + '_taux_remise').spinner({
                                                                                min: 0,
                                                                                max: 100,
                                                                                step: 1,
                                                                                places: 2,
                                                                                showOn: 'both'
                                                                            });
                                                                            $('#gds_ventebundle_' + i + '_quantite').spinner({
                                                                                min: 0,
                                                                                max: 10000,
                                                                                step: 1,
                                                                                places: 2,
                                                                                showOn: 'both'
                                                                            });
                                                                            article.remise_min = 0
                                                                            article.prix_vente_max_ttc = 999999999
                                                                        }
                                                                        $.ajax({
                                                                            url: '{{path('gds_vente_get_all_articles')}}',
                                                                            datatype: 'json',
                                                                            data: 'raison_social=' + '{{client}}',
                                                                            success: function(data) {
                                                                                $("#articles").tokenInput(data, {
                                                                                    preventDuplicates: true,
                                                                                    onAdd: function(item) {
                                                                                        item.remise_min = 0
                                                                                        item.prix_vente_max_ttc = 99999999999
                                                                                        item.quantite = 0
                                                                                        if (!item.quantite_retour) {
                                                                                            item.quantite1 = 0
                                                                                            item.quantite2 = 0
                                                                                            item.quantite_retour = 0
                                                                                        }
                                                                                        ajouterArticle(item)
                                                                                    },
                                                                                });
                                                                            }
                                                                        })
                                                                    }
                                                                }
                                                            })
                                                        }
                                                    }
                                                }
                                            });
                                        }
                                    })
                                })
                                function ajouterArticle(item) {
                                    $('.token-input-token').hide()
                                    var article = getArticle(item.id)
                                    if (!article) {
                                        add_ligne()
                                        var article = item.name.split(' : ');
                                        var reference = article[0]
                                        var designation = article[1]
                                        articles.push(item)
                                        var id = index - 1
                                        $('#td_reference_' + id).html(reference)
                                        $('#td_designation_' + id).html(designation)
                                        $('#gds_ventebundle_' + id + '_article').val(item.id)
                                        remplir_ligne(id, item)
                                        $('#gds_ventebundle_' + id + '_prix_unitaire_ht').change()
                                        var qte_prise = parseFloat(item.quantite1) + parseFloat(item.quantite2) - parseFloat(item.quantite_retour)
                                        $('#td_qte_prise_' + id).html(qte_prise.toFixed(2))
                                        if (!article_added) {
                                            $('#gds_ventebundle_' + id + '_quantite').spinner({
                                                min: 0,
                                                max: qte_prise,
                                                step: 1,
                                                places: 2,
                                                showOn: 'both'
                                            });
                                        } else {
                                            $('#gds_ventebundle_' + id + '_quantite').spinner({
                                                min: 0,
                                                max: 999999,
                                                step: 1,
                                                places: 2,
                                                showOn: 'both'
                                            });
                                            $('#gds_ventebundle_' + id + '_taux_remise').spinner({
                                                min: 0,
                                                max: 100,
                                                step: 1,
                                                places: 2,
                                                showOn: 'both'
                                            });
                                        }
                                    } else {
                                        id = article.index
                                    }
                                    $('#gds_ventebundle_' + id + '_quantite').focus()
                                }
                                function add_ligne() {
                                    var td_num = '<td class="numero_ligne" style="padding:0;text-align:center" id="td_num_' + index + '">' + nb_article + '</td>';
                                    var hidden_stock = '<input id="gds_ventebundle_' + index + '_article" type="hidden"/>';
                                    var td_reference = '<td style="padding:0;width:10%" id="td_reference_' + index + '"></td>';
                                    var td_designation = '<td style="padding:0;width:20%" id="td_designation_' + index + '"></td>';
                                    var td_qte = '<td style="padding:0" id="td_qte_' + index + '"><input class="quantite" style="padding:2%;width:60%" id="gds_ventebundle_' + index + '_quantite" type="text" value="0" onkeyup="Test(this)"></td>';
                                    var td_qte_prise = '<td style="padding:0" id="td_qte_prise_' + index + '"></td>';
                                    var td_prix_unitaire_ht = '<td style="padding:0" id="td_prix_unitaire_ht_' + index + '"><input style="padding:2%;width:95%" id="gds_ventebundle_' + index + '_prix_unitaire_ht" type="text" onkeyup="Test(this)"></td>';
                                    var td_tva = '<td style="padding:0" id="td_tva_' + index + '">18.00%</td>';
                                    var td_remise = '<td style="padding:0" id="td_remise_' + index + '"><input class="remise" style="padding:2%;width:60%" id="gds_ventebundle_' + index + '_taux_remise" type="text" onkeyup="Test(this)"></td>';
                                    var td_prix_u_ttc = '<td style="padding:0" id="td_prix_u_ttc_' + index + '"><input class="prix_u_ttc" style="padding:2%;width:95%" id="prix_u_ttc_' + index + '" type="text" onkeyup="Test(this)"></td>';
                                    var td_total = '<td style="padding:0;width:10%" id="td_total_' + index + '">0.000</td>';
                                    var td_delete = '<td style="padding:0" ><img src="/images/icons/delete.png" id="delete_ligne_' + index + '" onclick="delete_ligne(' + index + ')"></td>'
                                    var tr_contenu = td_num + td_reference + td_designation + hidden_stock + td_qte + td_qte_prise + td_prix_unitaire_ht + td_tva + td_remise + td_prix_u_ttc + td_total + td_delete;
                                    var tr = $('<tr id="tr_' + index + '">' + tr_contenu + '</tr>')
                                    $container.append(tr);
                                    index++
                                    nb_article++
                                    b = tr.attr('id')
                                    b = b.split('_')
                                    b = b[1]
                                    $('#gds_ventebundle_' + b + '_quantite').spinner({
                                        min: 0,
                                        max: 10000,
                                        step: 1,
                                        places: 2,
                                        showOn: 'both'
                                    });
                                    $('#gds_ventebundle_' + b + '_quantite').keyup(function() {
                                        var i = $(this).attr('id');
                                        i = i.split('_');
                                        i = i[2];
                                        quantite = $(this).val();
                                        var article = getArticle($('#gds_ventebundle_' + i + '_article').val())
                                        article.quantite = quantite
                                        prix_vente_ht = article.prix_vente;
                                        tva = article.taux_tva;
                                        remise = article.remise;
                                        puttc = prix_vente_ht
                                        puttc *= (1 + tva / 100)
                                        puttc *= (1 - remise / 100)
                                        $('#prix_u_ttc_' + i).val(puttc.toFixed(3));
                                        total = puttc * quantite
                                        $('#td_total_' + i).html(total.toFixed(3));
                                        RefraichirTaxe()
                                    });
                                    $('#gds_ventebundle_' + b + '_quantite').change(function() {
                                        var i = $(this).attr('id');
                                        i = i.split('_');
                                        i = i[2];
                                        quantite = $(this).val();
                                        var article = getArticle($('#gds_ventebundle_' + i + '_article').val())
                                        article.quantite = quantite
                                        prix_vente_ht = article.prix_vente;
                                        tva = article.taux_tva;
                                        remise = article.remise;
                                        puttc = prix_vente_ht
                                        puttc *= (1 + tva / 100)
                                        puttc *= (1 - remise / 100)
                                        $('#prix_u_ttc_' + i).val(puttc.toFixed(3));
                                        total = puttc * quantite
                                        $('#td_total_' + i).html(total.toFixed(3));
                                        RefraichirTaxe()
                                    });
                                    $('#gds_ventebundle_' + b + '_prix_unitaire_ht').keyup(function() {
                                        var i = $(this).attr('id');
                                        i = i.split('_');
                                        i = i[2];
                                        prix_vente_ht = $(this).val();
                                        var article = getArticle($('#gds_ventebundle_' + i + '_article').val())
                                        quantite = article.quantite
                                        tva = article.taux_tva;
                                        remise = article.remise;
                                        puttc = prix_vente_ht
                                        puttc *= (1 + tva / 100)
                                        puttc *= (1 - remise / 100)
                                        article.prix_vente = prix_vente_ht
                                        $('#prix_u_ttc_' + i).val(puttc.toFixed(3));
                                        total = puttc * quantite
                                        $('#td_total_' + i).html(total.toFixed(3));
                                        RefraichirTaxe()
                                    });
                                    $('#gds_ventebundle_' + b + '_prix_unitaire_ht').change(function() {
                                        var i = $(this).attr('id');
                                        i = i.split('_');
                                        i = i[2];
                                        prix_vente_ht = $(this).val();
                                        var article = getArticle($('#gds_ventebundle_' + i + '_article').val())
                                        quantite = article.quantite
                                        tva = article.taux_tva;
                                        remise = article.remise;
                                        puttc = prix_vente_ht
                                        puttc *= (1 + tva / 100)
                                        puttc *= (1 - remise / 100)
                                        if (puttc > article.prix_vente_max_ttc) {
                                            puttc = article.prix_vente_max_ttc
                                            prix_vente_ht = puttc / ((1 + tva / 100) * (1 - remise / 100))
                                            $(this).val(prix_vente_ht.toFixed(3))
                                        }
                                        var x = article.prix_vente_max_ttc / (prix_vente_ht * (1 + tva / 100))
                                        var remise_min = (1 - x) * 100
                                        article.remise_min = remise_min
                                        $('#gds_ventebundle_' + i + '_taux_remise').spinner({
                                            min: remise_min,
                                            max: 100,
                                            step: 1,
                                            places: 2,
                                            showOn: 'both'
                                        })
                                        var prix_vente_max_ttc = prix_vente_ht * (1 + tva / 100) * (1 - remise_min / 100)
                                        article.prix_vente_max_ttc = prix_vente_max_ttc
                                        article.prix_vente = prix_vente_ht
                                        $('#prix_u_ttc_' + i).val(puttc.toFixed(3));
                                        total = puttc * quantite
                                        $('#td_total_' + i).html(total.toFixed(3));
                                        RefraichirTaxe()
                                    })
                                    $('#gds_ventebundle_' + b + '_taux_remise').keyup(function() {
                                        var i = $(this).attr('id');
                                        i = i.split('_');
                                        i = i[2];
                                        doRemiseChange(i)
                                        RefraichirTaxe()
                                    });
                                    $('#gds_ventebundle_' + b + '_taux_remise').change(function() {
                                        var i = $(this).attr('id');
                                        i = i.split('_');
                                        i = i[2];
                                        doRemiseChange(i)
                                        RefraichirTaxe()
                                    });
                                    $('#gds_ventebundle_' + b + '_taux_remise').blur(function() {
                                        if (!$('.msgBoxTitle').html())
                                            $('#articles').focus()
                                    })

                                    $('#prix_u_ttc_' + b).keyup(function() {
                                        var i = $(this).attr('id');
                                        i = i.split('_');
                                        i = i[3];
                                        puttc = $(this).val();
                                        var article = getArticle($('#gds_ventebundle_' + i + '_article').val())
                                        prix_vente_ht = article.prix_vente;
                                        quantite = article.quantite;
                                        tva = article.taux_tva;
                                        prix_sans_remise_ttc = prix_vente_ht * (1 + tva / 100)
                                        if (prix_sans_remise_ttc != 0) {
                                            remise = (1 - puttc / prix_sans_remise_ttc) * 100
                                            remise = parseInt(remise)
                                        } else {
                                            remise = 100;
                                        }
                                        article.remise = remise
                                        $('#gds_ventebundle_' + i + '_taux_remise').val(remise.toFixed(2));
                                        total = puttc * quantite
                                        $('#td_total_' + i).html(total.toFixed(3));
                                        RefraichirTaxe()
                                    });
                                    $('#prix_u_ttc_' + b).change(function() {
                                        var i = $(this).attr('id');
                                        i = i.split('_');
                                        i = i[3];
                                        puttc = $(this).val();
                                        var article = getArticle($('#gds_ventebundle_' + i + '_article').val())
                                        if (puttc > article.prix_vente_max_ttc) {
                                            puttc = article.prix_vente_max_ttc
                                            $(this).val(puttc)
                                        }
                                        prix_vente_ht = article.prix_vente;
                                        quantite = article.quantite;
                                        tva = article.taux_tva;
                                        prix_sans_remise_ttc = prix_vente_ht * (1 + tva / 100)
                                        if (prix_sans_remise_ttc != 0) {
                                            remise = (1 - puttc / prix_sans_remise_ttc) * 100
                                            remise = parseInt(remise)
                                        } else {
                                            remise = 100;
                                        }
                                        article.remise = remise
                                        $('#gds_ventebundle_' + i + '_taux_remise').val(remise.toFixed(2));
                                        total = puttc * quantite
                                        $('#td_total_' + i).html(total.toFixed(3));
                                        RefraichirTaxe()
                                    });
                                    refraichir()
                                }
                                function Test(obj) {
                                    var data = obj.value;
                                    var d = data.substring(0, data.length - 1)
                                    var index_virgule = data.indexOf('.')
                                    if (index_virgule > 0)
                                        apres_virgule = data.substring(data.indexOf('.') + 1, data.length)
                                    if (!TestVerif(data) || apres_virgule.length > 3)
                                        obj.value = d
                                }
                                function TestVerif(decimal) {
                                    var entier = "0123456789"
                                    var virgule = false
                                    var first_number = false
                                    for (index_verif = 0; index_verif < decimal.length; index_verif++) {
                                        if (entier.indexOf(decimal[index_verif]) < 0) {
                                            if (decimal[index_verif] == '.' && first_number) {
                                                if (virgule)
                                                    return false
                                                else
                                                    virgule = true
                                            } else {
                                                return false
                                            }
                                        } else {
                                            first_number = true
                                        }
                                    }
                                    return true
                                }
                                function remplir_ligne(id, item) {
                                    $('#gds_ventebundle_' + id + '_prix_unitaire_ht').val(item.prix_vente)
                                    $('#gds_ventebundle_' + id + '_taux_remise').val(item.remise)
                                    $('#td_tva_' + id).html(item.taux_tva + '%')
                                }
                                function delete_ligne(index) {
                                    var article = getArticle($('#gds_ventebundle_' + index + '_article').val())
                                    var cmp_delete = 0
                                    var article_deleted = false
                                    while (!article_deleted && cmp_delete < articles.length) {
                                        if (articles[cmp_delete] == article) {
                                            articles.splice(cmp_delete, 1)
                                            article_deleted = true
                                        }
                                        cmp_delete++
                                    }
                                    $('#tr_' + index).remove();
                                    $('.token-input-list li').each(function() {
                                        var name = article.reference + ' : ' + article.designation
                                        if ($(this).children("p").html() == name)
                                            $(this).remove()
                                    })
                                    refraichir()
                                    RefraichirTaxe()
                                }
                                function refraichir() {
                                    i = 1
                                    $('.numero_ligne').each(function() {
                                        $(this).html(i)
                                        i++
                                    })
                                }
                                function getArticle(id) {
                                    for (i = 0; i < articles.length; i++) {
                                        if (articles[i].id == id) {
                                            return articles[i]
                                        }
                                    }
                                    return null
                                }
                                function inverser(tab, i, j, tab2) {
                                    temp = tab[i];
                                    base = tab2[i]['base']
                                    montant = tab2[i]['montant']
                                    tva = tab2[i]['tva']
                                    tab[i] = tab[j];
                                    tab[j] = temp;
                                    tab2[i]['base'] = tab2[j]['base']
                                    tab2[j]['base'] = base
                                    tab2[i]['montant'] = tab2[j]['montant']
                                    tab2[j]['montant'] = montant
                                    tab2[i]['tva'] = tab2[j]['tva']
                                    tab2[j]['tva'] = tva
                                }
                                function TriTab(tab, tab2) {
                                    n = tab.length;
                                    continuer = true;
                                    i = 0;
                                    iter = 0;
                                    while (continuer) {
                                        iter++;
                                        continuer = false;
                                        for (i = 0; i < n - 1; i++) {
                                            if (Math.max(tab[i], tab[i + 1]) != tab[i + 1]) {
                                                inverser(tab, i, i + 1, tab2);
                                                continuer = true;
                                            }
                                        }
                                    }
                                    return tab2;
                                }
                                function RefraichirTaxe() {
                                    var rowCount = $('#gds_ventebundle_lignebonretour tr').length
                                    var total_ttc = 0
                                    var taux_tva = new Array();
                                    var taxes = new Array();
                                    for (i = 0; i < rowCount; i++) {
                                        taxes[i] = new Array()
                                        taxes[i]['tva'] = 0
                                        taxes[i]['base'] = 0
                                        taxes[i]['montant'] = 0
                                    }
                                    var cmp = 0
                                    var i_refraich = 0
                                    while (cmp < rowCount) {
                                        if ($('#td_total_' + i_refraich).html() != null) {
                                            var tva = parseFloat($('#td_tva_' + i_refraich).html())
                                            if (parseFloat($('#td_total_' + i_refraich).html()) > 0) {
                                                j = $.inArray(tva, taux_tva)
                                                if (j == -1) {
                                                    taux_tva.push(tva)
                                                    j = $.inArray(tva, taux_tva)
                                                }
                                                ttc = parseFloat($('#td_total_' + i_refraich).html())
                                                total_ttc += ttc
                                                ht = ttc / (1 + tva / 100)
                                                montant = ht * tva / 100
                                                taxes[j]['tva'] = tva
                                                taxes[j]['base'] += ht
                                                taxes[j]['montant'] += montant
                                            }
                                            cmp++
                                        }
                                        i_refraich++
                                    }
                                    taxes = TriTab(taux_tva, taxes)
                                    $('#taxe_body tr').remove()
                                    var totaux = 0
                                    for (i = 0; i < taux_tva.length; i++) {
                                        tva = taxes[i]['tva'].toFixed(2)
                                        totaux += taxes[i]['montant']
                                        $('#taxe_body').append('<tr id="tr_taxe_' + tva + '"><td id="taxe_' + tva + '">' + tva + '%</td><td id="base_' + tva + '">' + taxes[i]['base'].toFixed(3) + '</td><td id="montant_taxe_' + tva + '">' + taxes[i]['montant'].toFixed(3) + '</td></tr>');
                                    }
                                    $('#taxe_body').append('<tr><td>Totaux</td><td></td><td id="total_taxe">' + totaux.toFixed(3) + '</td></tr>');
                                    $('#total_ttc').html(total_ttc.toFixed(3))
                                }
                                function doRemiseChange(i) {
                                    var article = getArticle($('#gds_ventebundle_' + i + '_article').val())
                                    article.remise = $('#gds_ventebundle_' + i + '_taux_remise').val()
                                    quantite = article.quantite;
                                    prix_vente_ht = article.prix_vente;
                                    tva = article.taux_tva;
                                    puttc = prix_vente_ht
                                    puttc *= (1 + tva / 100)
                                    puttc *= (1 - article.remise / 100)
                                    $('#prix_u_ttc_' + i).val(puttc.toFixed(3));
                                    total = puttc * quantite
                                    $('#td_total_' + i).html(total.toFixed(3));
                                }
                                function time() {
                                    var time = new Date($.now())
                                    h = time.getHours() // 0-24 format
                                    m = time.getMinutes()
                                    s = time.getSeconds()
                                    $('#heure').val(s + m * 60 + h * 3600)
                                    if (h < 10)
                                        h = '0' + h
                                    if (m < 10)
                                        m = '0' + m
                                    if (s < 10)
                                        s = '0' + s
                                    $('#now').val(h + ':' + m + ':' + s)
                                }
                                function EnregistrerImprimer() {
                                    imprimer()
                                    Enregistrer()
                                }
                                function imprimer() {
                                    alert('impression')

                                }
                </script>
                <style>
                        .red {
                            color: red;
                            font-size: 18px;
                        }
                        .green{
                            color : green;
                        }
                    </style>